﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PokeData;

namespace PokeTD
{
    /// <summary>
    /// Klasse für einen Block/ein Tile auf der Map
    /// </summary>
    class Block
    {
        public static int BlockWidth = 32;
        public static int BlockHeight = 32;
        private int _TileID;
        private Vector2 _Position;
        private bool _hasTower;
        //public bool walkable; <- braucht man nicht, da das aus der TileID bzw. aus hasTower folgt.
        private int _distance;
        private Block _bestNeighbor;
        private bool _lookedAt;

        /// <summary>
        /// Erstellt einen Block
        /// </summary>
        /// <param name="TileID">Tile-ID</param>
        /// <param name="position">Position des Blocks</param>
        public Block(int TileID, Vector2 position) {
            this.TileID = TileID;
            Position = position;
            HasTower = false;
            Distance = -1;
            BestNeighbor = null;
            LookedAt = false;
        }

        /// <summary>
        /// Setzt Markierungen für Pfadfindung zurück.
        /// </summary>
        public void reset() {
            Distance = -1;
            BestNeighbor = null;
            LookedAt = false;
        }

        public int TileID {
            get { return this._TileID; }
            set { this._TileID = value; }
        }

        public Vector2 Position {
            get { return this._Position; }
            set { this._Position = value; }
        }
        public int X
        {
            get
            {
                return (int)Position.X;
            }
            set
            {
                _Position.X = value;
            }
        }
        public int Y
        {
            get
            {
                return (int)Position.Y;
            }
            set
            {
                _Position.Y = value;
            }
        }

        public bool HasTower {
            get { return _hasTower; }
            set { _hasTower = value; }
        }

        public int Distance {
            get { return _distance; }
            set { 
                _distance = value;
                LookedAt = true;
            }
        }

        public Block BestNeighbor {
            get { return _bestNeighbor; }
            set { _bestNeighbor = value; }
        }
        public bool LookedAt {
            get { return _lookedAt; }
            set { _lookedAt = value; }
        }

        /// <summary>
        /// Überprüft, ob Block frei ist.
        /// </summary>
        /// <returns>true, wenn frei, sonst false.</returns>
        public bool isWalkable() {
            if (HasTower) return false;
            //switch (TileID) {
            //    case 0: return false;
            //    case 1:
            //    case 2:
            //    case 3: return true;
            //    case 4:
            //    case 5:
            //    case 6:
            //    case 7:
            //    case 8: 
            //    case 9:
            //    case 10: return false;
            //    case 11:
            //    case 12:
            //    case 13:
            //    case 14:
            //    case 15:
            //    case 16:
            //    case 17:
            //    case 18:
            //    case 19:
            //    case 20:
            //    case 21:
            //    case 22:
            //    case 23:
            //    case 24:
            //    case 25:
            //    case 26:
            //    case 27:
            //    case 28: return true;
            //    default: return false;
            //}
            var q = from a in Globals.tilesetDS.Tile
                    where a.id == TileID
                    select a.isWalkable;

            return q.First<bool>();
        }
    }
}
